package com.ocom.webapi.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.ocom.common.constant.MapKey;
import com.ocom.common.dto.Department;
import com.ocom.common.entity.access.EntityDeptInfo;
import com.ocom.common.entity.human.EntityPersonnelInfo;
import com.ocom.common.entity.human.EntityRoommateInfo;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.*;
import com.ocom.common.vo.webapi.ExcelAddPersonVo;
import com.ocom.redis.util.RedisUtil;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.AccessClientService;
import com.ocom.webapi.feign.HumanClientService;
import com.ocom.webapi.feign.MqSimpleService;
import com.ocom.webapi.service.StudentPageService;
import com.ocom.webapi.vo.studentpage.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.hutool.poi.excel.cell.CellUtil.getCellValue;


@Service
public class StudentPageServiceImpl implements StudentPageService {

    private final Logger log = LoggerFactory.getLogger(StudentPageService.class);
    @Autowired
    private HumanClientService humanClientService;

    @Resource
    private RedisUtil redisUtil;


    @Autowired
    AccessClientService accessClientService;

    @Autowired
    MqSimpleService mqSimpleService;

    /**
     * 人员列表（StudentPage/onShow）
     * */
    @Override
    public Result StudentPageOnShow(OnShowVo onShowVo) {
        Map<String, Object> map = new HashMap<>();

        MapKey mapKey = new MapKey();
        Department department=new Department();
        department.setComId(SecurityUtils.getYoCiUser().getComId());
        department.setDeptId(onShowVo.getDeptId());
        department.setShowLevel(0);
        Result result=humanClientService.getDeptIds(department);
        if (result.getCode()!=200){
            return ResultUtil.error(result.getCode());
        }
        map.put(mapKey.getKey_deptIds(),onShowVo.getDeptId()+","+JSON.parseObject(JSON.toJSONString(result.getData())).getString("deptIds"));
        map.put(mapKey.getKey_comId(), SecurityUtils.getYoCiUser().getComId());
        map.put(mapKey.getKey_pCode(),onShowVo.getPCode());
        map.put(mapKey.getKey_pName(),onShowVo.getPName());
        map.put(mapKey.getKey_page(),onShowVo.getPage());
        map.put(mapKey.getKey_size(),onShowVo.getSize());
        map.put(mapKey.getKey_status(),0);
        map.put(mapKey.getKey_roomPerson(),onShowVo.getRoomPerson());
        map.put("regionId",onShowVo.getRegionId());
        map.put("regionOrigId",onShowVo.getRegionOrigId());
        map.put("regionOnline",onShowVo.getRegionOnline());
        map.put("pType",onShowVo.getPType());
        log.info("人员列表,map{{}}",map);
        return humanClientService.PersonnelGetStudentInfo(map);
    }


    /**
     * 人员信息（StudentPage/info）
     * */
    @Override
    public Result StudentPageInfo(Long comId, Long pId) {
        return humanClientService.GetPersonInfo(comId,pId);
    }
    /**
     * 新增人员信息（StudentPage/add）
     * */
    @Override
    public Result StudentPageAdd(AddVo addVo) {
        Map<String, Object> map = new HashMap<>();
        MapKey mapKey = new MapKey();
        map.put(mapKey.getKey_comId(),SecurityUtils.getYoCiUser().getComId());
        map.put(mapKey.getKey_deptId(),addVo.getDeptId());
        map.put(mapKey.getKey_deptName(),addVo.getDeptName());
        map.put(mapKey.getKey_pCode(),addVo.getPCode());
        map.put(mapKey.getKey_pPwd(),addVo.getPPwd());
        map.put(mapKey.getKey_pName(),addVo.getPName());
        map.put(mapKey.getKey_pSex(),addVo.getPSex());
        map.put(mapKey.getKey_pType(),addVo.getPType());
        map.put(mapKey.getKey_pPhone(),addVo.getPPhone());
        map.put(mapKey.getKey_pIdentity(),addVo.getPIdentity());
        map.put(mapKey.getKey_pBorn(),addVo.getPBorn());
        map.put(mapKey.getKey_pAddress(),addVo.getPAddress());
        map.put(mapKey.getKey_pPhotoUrl(),addVo.getPPhotoUrl());
        map.put(mapKey.getKey_status(),addVo.getStatus());

        if (!IdentificationCodeUtil.isIdentityCode(addVo.getPIdentity())){
            return ResultUtil.error(ResultEnum.Err_2021);
        }
        Gson gson =new Gson();
        Map<String,String> mapUser= new HashMap<>();
        mapUser.put("name",addVo.getPName());
        mapUser.put("identitycard_No",addVo.getPIdentity());
        redisUtil.leftPush("timerCompany:"+addVo.getComId()+":0",gson.toJson(map),82800l);

        return humanClientService.AddPerson(map);
    }

    /**
     * 修改人员信息（StudentPage/modify）
     * */
    @Override
    public Result StudentPageModify(ModifyVo modifyVo) {
        Map<String, Object> map = new HashMap<>();
        MapKey mapKey = new MapKey();
        map.put(mapKey.getKey_comId(),SecurityUtils.getYoCiUser().getComId());
        map.put(mapKey.getKey_deptId(),modifyVo.getDeptId());
        map.put(mapKey.getKey_deptName(),modifyVo.getDeptName());
        map.put(mapKey.getKey_pId(),modifyVo.getPId());
        map.put(mapKey.getKey_pCode(),modifyVo.getPCode());
        map.put(mapKey.getKey_pPwd(),modifyVo.getPPwd());
        map.put(mapKey.getKey_pName(),modifyVo.getPName());
        map.put(mapKey.getKey_pSex(),modifyVo.getPSex());
        map.put(mapKey.getKey_pType(),modifyVo.getPType());
        map.put(mapKey.getKey_pPhone(),modifyVo.getPPhone());
        map.put(mapKey.getKey_pIdentity(),modifyVo.getPIdentity());
        map.put(mapKey.getKey_pBorn(),modifyVo.getPBorn());
        map.put(mapKey.getKey_pAddress(),modifyVo.getPAddress());
        map.put(mapKey.getKey_pPhotoUrl(),modifyVo.getPPhotoUrl());
        map.put(mapKey.getKey_status(),modifyVo.getStatus());

        if (!CommonUtil.isNull(modifyVo.getPIdentity()) &&  !IdentificationCodeUtil.isIdentityCode(modifyVo.getPIdentity())){
            return ResultUtil.error(ResultEnum.Err_2021);
        }

        return humanClientService.UpdatePerson(map);
    }
    /**
     * 人员删除（StudentPage/delete）
     * */
    @Override
    public Result StudentPageDelete(DeleteVo deleteVo) {
        Long companyId = SecurityUtils.getYoCiUser().getComId();
        Long userId = deleteVo.getPId();
        Result result = humanClientService.removePerson(companyId,0L,userId);
        if(result.getCode()!=200){
            return ResultUtil.error(result.getCode());
        }
        //移除白名单
        accessClientService.clearAccessByUser(companyId,0L,userId);
        return ResultUtil.success();
    }

    @Override
    public Result StudentPageImport(Long comId, String areaGroop, MultipartFile file) {

        //        1、用HSSFWorkbook打开或者创建“Excel文件对象”
        //        2、用HSSFWorkbook对象返回或者创建Sheet对象
        //        3、用Sheet对象返回行对象，用行对象得到Cell对象
        //        4、对Cell对象读写。
        //获得文件名
        Workbook workbook = null ;
        String fileName = file.getOriginalFilename();
        if(fileName.endsWith("xls")){
            //2003
            try {
                workbook = new HSSFWorkbook(file.getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else if(fileName.endsWith("xlsx")){
            //2007
            try {
                workbook = new XSSFWorkbook(file.getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            try {
                throw new Exception("文件不是Excel文件");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        Sheet sheet = workbook.getSheetAt(0);
        int rows = sheet.getLastRowNum();// 指的行数，一共有多少行+
        if(rows==0){
            try {
                throw new Exception("请填写数据");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

//        List<EntityPersonnelInfo> entityPersonnelInfos = new ArrayList<>();
        List<Map> errList = new ArrayList<>();
        Gson gson =new Gson();

        Long timestamp = System.currentTimeMillis();
        Map<String,Object> map1=new HashMap<>();
        map1.put("key","ImportErr:detail:"+comId+":"+timestamp);
        map1.put("type",2);
        map1.put("name","学生批量导入");
        map1.put("timestamp",timestamp);
        map1.put("datetime", DateUtil.getDateTime());
        redisUtil.leftPush("ImportErr:"+comId,map1,86400l);


        List<EntityDeptInfo> list= new ArrayList<>();
        //获取完整部门树
        Result result2 = humanClientService.getDeptList(comId,0l,1);

        if(result2.getCode()!=200){
            return ResultUtil.error(ResultEnum.Err_302);
        }

        list = JSON.parseArray(JSON.toJSONString(result2.getData()), EntityDeptInfo.class);

        //获取所有片区
        JSONObject jsonObject2=new JSONObject();
        jsonObject2.put("comId",SecurityUtils.getYoCiUser().getComId());
        List<JSONObject> objectList=new ArrayList<>();

        Result result3 = accessClientService.getRegionInfo(jsonObject2);
        if(result3.getCode()==200){
            JSONObject studentJSON =JSON.parseObject(JSON.toJSONString(result3.getData()));
            objectList=JSON.parseArray(JSON.toJSONString(studentJSON.get("list")),JSONObject.class);
        }



        for (int i = 1; i < rows+1; i++) {
            MapKey mapKey = new MapKey();
            EntityPersonnelInfo entityPersonnelInfo = new EntityPersonnelInfo();
            Map<String, Object> map = new HashMap<>();
            entityPersonnelInfo.setComId(SecurityUtils.getYoCiUser().getComId());
            // 读取左端单元格
            Row row = sheet.getRow(i);
            // 行不为空
            if (row != null) {

                String errMsg = "";

                // **读取cell**
                //姓名
                String pName = JSON.toJSONString(getCellValue(row.getCell(0))).replace("\"", "").replace("\\t", "");
                pName=pName.replace("\\t","");
                if (StringUtils.isNotEmpty(pName) && !pName.equals("null")){
                    entityPersonnelInfo.setPName(pName);
                }else{
                    errMsg += "姓名为空,";
                }


                // 性别(男/女)
                String pSex = JSON.toJSONString(getCellValue(row.getCell(1))).replace("\"", "").replace("\\t", "");
                pSex=pSex.replace("\\t","");
                if (pSex.equals("男")) {
                    entityPersonnelInfo.setPSex(0);
                } else if (pSex.equals("女")) {
                    entityPersonnelInfo.setPSex(1);
                }

                // 人员编号
                String pCode = JSON.toJSONString(getCellValue(row.getCell(2))).replace("\"", "").replace("\\t", "");
                pCode=pCode.replace("\\t","");
                if (StringUtils.isNotEmpty(pCode) && !pCode.equals("null")){
                    entityPersonnelInfo.setPCode(pCode);
                }else{
                    errMsg += "编号为空,";
                }

                // 人员编号
                Long grade = 0L;
                String deptName = JSON.toJSONString(getCellValue(row.getCell(3))).replace("\"", "").replace("\\t", "");
                String[] deptNameSplit = deptName.split("/");

                entityPersonnelInfo.setDeptId(0l);

                if(deptNameSplit.length<=0){
                    map.put(mapKey.getKey_pName(),pName);
                    map.put(mapKey.getKey_deptName(),deptName);
                    map.put(mapKey.getKey_pIdentity(), "");
                    errList.add(map);

                }else {
                    Long realDeptId=0l;
                    Long parentDeptId=0l;
                    outterLoop: for (String ndeptName:deptNameSplit){
                        Boolean exist=false;
                        for (EntityDeptInfo entityDeptInfo:list){
                            //匹配到名称
                            if(entityDeptInfo.getDeptName().equals(ndeptName) &&
                                    entityDeptInfo.getParentDeptId().equals(parentDeptId)){
                                exist=true;
                                parentDeptId = entityDeptInfo.getDeptId();
                                realDeptId = entityDeptInfo.getDeptId();
                                break ;
                            }
                        }
                        if(!exist){
                            map.put(mapKey.getKey_pName(),pName);
                            map.put(mapKey.getKey_deptName(),deptName);
                            map.put(mapKey.getKey_pIdentity(), "");
                            errList.add(map);
                            realDeptId= 0l;

                            errMsg += "部门未匹配到,";

                            break  outterLoop;
                        }
                    }
                    entityPersonnelInfo.setDeptId(realDeptId);
                }



//                for (int i1 = 0; i1 < deptNameSplit.length; i1++) {
//                    deptName = deptNameSplit[i1];
//                    grade++;
//                }
//                Long deptID = null;
//                Result result = humanClientService.GetDeptInfo(comId, deptID, deptName);
//                if (result.getCode() == 200) {
//                    List<EntityDeptInfo> entityDeptInfos = JSON.parseArray(JSON.toJSONString(result.getData()), EntityDeptInfo.class);
//                    if (entityDeptInfos.size() == 0) {
//                        entityPersonnelInfo.setDeptId(0L);
//                    }
//                    for (EntityDeptInfo entityDeptInfo : entityDeptInfos) {
//                        if (entityDeptInfo.getDeptName().equals(deptName)  || entityDeptInfo.getGrade().equals(grade)) {
//                            entityPersonnelInfo.setDeptId(entityDeptInfo.getDeptId());
//                        }
//                    }
//                }

                // 人员类型(职工/教师/学生)
                String pType = JSON.toJSONString(getCellValue(row.getCell(4))).replace("\"", "").replace("\\t", "");
                pType=pType.replace("\\t","");
                if (pType.equals("职工")) {
                    entityPersonnelInfo.setPType(102L);
                } else if (pType.equals("教师")) {
                    entityPersonnelInfo.setPType(103L);
                }else if (pType.equals("学生")){
                    entityPersonnelInfo.setPType(104L);
                }

                //人员密码
                String pPwd= JSON.toJSONString(getCellValue(row.getCell(5))).replace("\"", "").replace("\\t", "");
                entityPersonnelInfo.setPPwd("");
                if (StringUtils.isNotEmpty(pPwd) && !pPwd.equals("null")){
                    entityPersonnelInfo.setPPwd(pPwd);
                }

                // 联系电话
                String pPhone = JSON.toJSONString(getCellValue(row.getCell(6))).replace("\"", "").replace("\\t", "");
                pPhone=pPhone.replace("\\t","");
                if (StringUtils.isNotEmpty(pPhone) && !pPhone.equals("null")){
                    entityPersonnelInfo.setPPhone(pPhone);
                }else{
                    errMsg += "电话为空,";
                }

                // 身份证号码
                String pIdentity = JSON.toJSONString(getCellValue(row.getCell(7))).replace("\"", "").replace("\\t", "");
                pIdentity=pIdentity.replace("\\t","");
                if (pIdentity.length() != 18 || pIdentity.isEmpty() || pIdentity.equals("null")) {
                    map.put(mapKey.getKey_pName(),pName);
                    map.put(mapKey.getKey_deptName(),deptName);
                    map.put(mapKey.getKey_pIdentity(), pIdentity);
                    errList.add(map);

                    errMsg += "身份证为空或长度不对,";

                }else {
                    if (!IdentificationCodeUtil.isIdentityCode(pIdentity)){
                        map.put(mapKey.getKey_pName(),pName);
                        map.put(mapKey.getKey_deptName(),deptName);
                        map.put(mapKey.getKey_pIdentity(), pIdentity);
                        errList.add(map);

                        errMsg += "身份证校验不过,";
                    }else{
                        entityPersonnelInfo.setPIdentity(pIdentity);
                        Map<String,String> mapUser= new HashMap<>();
                        mapUser.put("name",pName);
                        mapUser.put("identitycard_No",pIdentity);
                        redisUtil.leftPush("timerCompany:"+comId+":0",gson.toJson(map),82800l);
                    }
                }
                // 住址
                String pAddress = JSON.toJSONString(getCellValue(row.getCell(8))).replace("\"", "").replace("\\t", "");
                if (StringUtils.isNotEmpty(pAddress) && pAddress.equals("null")){
                    entityPersonnelInfo.setPAddress(pAddress);
                }
                //人员图片地址
                String pPhotoUrl = JSON.toJSONString(getCellValue(row.getCell(9))).replace("\"", "").replace("\\t", "");
                if (StringUtils.isNotEmpty(pPhotoUrl) && pAddress.equals("null")){
                    entityPersonnelInfo.setPPhotoUrl(pPhotoUrl);
                }

                //校区
                String regionName = JSON.toJSONString(getCellValue(row.getCell(10))).replace("\"", "").replace("\\t", "");
                entityPersonnelInfo.setRegionOrigId(0l);
                if (StringUtils.isNotEmpty(regionName)){
                    for (JSONObject jsonObject6:objectList){
                        String  regionNameNl = jsonObject6.getString("regionName");
                        Long  regionId = jsonObject6.getLong("regionId");
                        if(regionNameNl!=null && regionName.equals(regionNameNl)){
                            entityPersonnelInfo.setRegionOrigId(regionId);
                            break;
                        }
                    }

//                    JSONObject jsonObject = new JSONObject();
//                    jsonObject.put("comId",comId);
//                    jsonObject.put("regionName",regionName);
//                    jsonObject.put("page",0);
//                    jsonObject.put("size",0);
//                    Result regionInfo = accessClientService.getRegionInfo(jsonObject);
//                    if (regionInfo.getCode()==200){
//                        List<Map> lists = JSON.parseArray(JSON.parseObject(JSON.toJSONString(regionInfo.getData())).get("list").toString(), Map.class);
//                        for (Map map2: lists) {
//
//                            entityPersonnelInfo.setRegionOrigId(Long.valueOf(map2.get("regionId").toString()));
//                        }
//                    }
                }
                if(!CommonUtil.isNull(errMsg)){
                    Map<String,Object> map3=new HashMap<>();
                    map3.put("errMsg",errMsg);
                    map3.put("json",entityPersonnelInfo);
                    redisUtil.leftPush("ImportErr:detail:"+comId+":"+timestamp,map3,86400l);
                }
            }


            if(CommonUtil.isNull(entityPersonnelInfo.getPAddress())){
                entityPersonnelInfo.setPAddress(null);
            }

            if(CommonUtil.isNull(entityPersonnelInfo.getPPhotoUrl())){
                entityPersonnelInfo.setPPhotoUrl(null);
            }

            List<EntityPersonnelInfo> entityPersonnelInfos = new ArrayList<>();
            entityPersonnelInfos.add(entityPersonnelInfo);

            ExcelAddPersonVo excelAddPersonVo =new ExcelAddPersonVo();
            excelAddPersonVo.setTimestamp(timestamp);
            excelAddPersonVo.setComId(comId);
            excelAddPersonVo.setAreaGroop(areaGroop);
            excelAddPersonVo.setPersonnelInfos(entityPersonnelInfos);
//            humanClientService.ImportUserInfo(excelAddPersonVo);
            mqSimpleService.ImportPerson(excelAddPersonVo);
        }

//        ExcelAddPersonVo excelAddPersonVo =new ExcelAddPersonVo();
//        excelAddPersonVo.setTimestamp(timestamp);
//        excelAddPersonVo.setComId(comId);
//        excelAddPersonVo.setAreaGroop(areaGroop);
//        excelAddPersonVo.setPersonnelInfos(entityPersonnelInfos);
//        humanClientService.ImportUserInfo(excelAddPersonVo);

//         humanClientService.ImportUserInfo(comId,timestamp, areaGroop,entityPersonnelInfos);
//        System.out.println(entityPersonnelInfos);


        return ResultUtil.success(errList);
    }
    /**
     * 导入同住人员（StudentPage/boardersImport）
     * */
    @Override
    public Result StudentPageBoardersImporte(Long comId, MultipartFile file) {
        //        1、用HSSFWorkbook打开或者创建“Excel文件对象”
        //        2、用HSSFWorkbook对象返回或者创建Sheet对象
        //        3、用Sheet对象返回行对象，用行对象得到Cell对象
        //        4、对Cell对象读写。
        //获得文件名
        Workbook workbook = null ;
        String fileName = file.getOriginalFilename();
        assert fileName != null;
        if(fileName.endsWith("xls")){
            //2003
            try {
                workbook = new HSSFWorkbook(file.getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else if(fileName.endsWith("xlsx")){
            //2007
            try {
                workbook = new XSSFWorkbook(file.getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            try {
                throw new Exception("文件不是Excel文件");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        assert workbook != null;
        Sheet sheet = workbook.getSheetAt(0);
        int rows = sheet.getLastRowNum();// 指的行数，一共有多少行+
        if(rows==0){
            try {
                throw new Exception("请填写数据");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        List<BoardersImportVo> boardersImportVos = new ArrayList<>();
        List<Map> errList = new ArrayList<>();
        Gson gson =new Gson();

        for (int i = 1; i < rows+1; i++) {
            MapKey mapKey = new MapKey();
            BoardersImportVo boardersImportVo = new BoardersImportVo();
            Map<String, Object> map = new HashMap<>();
            // 读取左端单元格
            Row row = sheet.getRow(i);
            // 行不为空
            if (row != null) {

                // **读取cell**
                // 人员编号
                String pCode = JSON.toJSONString(getCellValue(row.getCell(0))).replace("\"", "").replace("\\t", "");
                if (StringUtils.isNotEmpty(pCode) && !pCode.equals("null")){
                    boardersImportVo.setPCode(pCode);
                }

                //姓名
                String name = JSON.toJSONString(getCellValue(row.getCell(1))).replace("\"", "").replace("\\t", "");
                if (StringUtils.isNotEmpty(name) && !name.equals("null")){
                    boardersImportVo.setName(name);
                }


                // 联系电话
                String phone = JSON.toJSONString(getCellValue(row.getCell(2))).replace("\"", "").replace("\\t", "");
                if (StringUtils.isNotEmpty(phone) && !phone.equals("null")){
                    boardersImportVo.setPhone(phone);
                }

                // 身份证号码
                String identity = JSON.toJSONString(getCellValue(row.getCell(3))).replace("\"", "").replace("\\t", "");
                if (identity.length() != 18 || name.isEmpty() || name.equals("null")) {
                    map.put(mapKey.getKey_name(),name);
                    map.put(mapKey.getKey_identity(), identity);
                    errList.add(map);
                }else {
                    if (!IdentificationCodeUtil.isIdentityCode(identity)){
                        map.put(mapKey.getKey_pName(),name);
                        map.put(mapKey.getKey_identity(), identity);
                        errList.add(map);
                    }else{
                        boardersImportVo.setIdentity(identity);
                        Map<String,String> mapUser= new HashMap<>();
                        mapUser.put("name",name);
                        mapUser.put("identitycard_No",identity);
                        redisUtil.leftPush("timerCompany:"+comId+":0",gson.toJson(map),82800l);
                    }
                }
                // 关系名称
                String type = JSON.toJSONString(getCellValue(row.getCell(4))).replace("\"", "").replace("\\t", "");
                if (StringUtils.isNotEmpty(type) && !type.equals("null")){
                    boardersImportVo.setType(type);
                }
            }
            boardersImportVos.add(boardersImportVo);
        }
        humanClientService.ImportBorders(SecurityUtils.getYoCiUser().getComId(),boardersImportVos);

        return ResultUtil.success();
    }
    /**
     * 同住人员列表（StudentPage/boardersList）
     * */
    @Override
    public Result StudentPageBoardersList(Long comId, Long pId) {
        Map<String, Object> map = new HashMap<>();
        MapKey mapKey = new MapKey();
        map.put(mapKey.getKey_comId(),SecurityUtils.getYoCiUser().getComId());
        map.put(mapKey.getKey_pId(),pId);
        map.put(mapKey.getKey_page(),0);
        map.put(mapKey.getKey_size(),0);
        return humanClientService.GetRoommateList(map);
    }

    /**
     * 删除同住人员（StudentPage/boardersDelete）
     * */
    @Override
    public Result StudentPageBoardersDelete(BoardersDeleteVo boardersDeleteVo) {
        Map<String, Object> map = new HashMap<>();
        MapKey mapKey = new MapKey();
        map.put(mapKey.getKey_comId(),SecurityUtils.getYoCiUser().getComId());
        map.put(mapKey.getKey_id(),boardersDeleteVo.getId());
        map.put(mapKey.getKey_pId(),boardersDeleteVo.getPId());

        return humanClientService.RemoveRoommate(map);
    }
    /**
     * 新增同住人员（StudentPage/boardersAdd）
     * */
    @Override
    public Result StudentPageBoardersAdd(BoardersAddVo boardersAddVo) {
        EntityRoommateInfo entityRoommateInfo = new EntityRoommateInfo();
        entityRoommateInfo.setComId(SecurityUtils.getYoCiUser().getComId());
        entityRoommateInfo.setName(boardersAddVo.getName());
        entityRoommateInfo.setIdentity(boardersAddVo.getIdentity());
        String key = MD5.MD5Encode(boardersAddVo.getComId().toString(), "utf8");
        entityRoommateInfo.setEncryIdentity(AES.encrypt(boardersAddVo.getIdentity(),key));
        if (boardersAddVo.getPhone()!=null||StringUtils.isNotEmpty(boardersAddVo.getPhone())){
            entityRoommateInfo.setPhone(boardersAddVo.getPhone());
            entityRoommateInfo.setEncryPhone(AES.encrypt(boardersAddVo.getPhone(),key));
        }
        entityRoommateInfo.setType(boardersAddVo.getType());
        entityRoommateInfo.setPId(boardersAddVo.getPId());
        return humanClientService.AddRoommate(entityRoommateInfo);
    }

}
